package com.anlu.concurrent.ch1.safened;

/**
 * <p>
 * Description:中断Runnable类型的线程
 * <p>
 * Copyright: 天津联想协同科技有限公司
 * <p>
 *
 * @author anlu
 * @date 2021/9/3 16:13
 */
public class EndRunnable {
    private static class UseRunnable implements Runnable{

        @Override
        public void run() {
            // 线程的名称
            String threadName = Thread.currentThread().getName();
            while (!Thread.currentThread().isInterrupted()){
                System.out.println(threadName+" is run!");
            }
            System.out.println(threadName+" interrput flag is "
                    +Thread.currentThread().isInterrupted());

        }
    }

    public static void main(String[] args) throws InterruptedException {
        UseRunnable useRunnable = new UseRunnable();
        Thread endThread = new Thread(useRunnable,"endThread");
        endThread.start();
        Thread.sleep(20);
        endThread.interrupt();
    }
}
